// this is an example of how to use template SVector and SVectorIndex
#include "s-vector.h"

#include <string>
#include <sstream>
using namespace std;

#include "dictmap.h"

class SID; // Symbol ID class forward declaration
// this is vector of symbols with SID as indexing type
typedef SVector<SID, string> SymbolVector;
// this is Symbol ID class definition.
class SID : public SVectorIndex<SymbolVector> { 
  enum { WRONG_SID = 0}; 
};
class SymbolTable {
public:
  SymbolVector symbols;
  DictMap<string, SID> symbols_dict;
  void init() {
    symbols.push_back("");
    for (int c = 0; c < 10; c++) {
	ostringstream m; 
	m << "S" << c;
	symbols_dict.set(m.str(), symbols.end());
	symbols.push_back(m.str());
      }
	   }
    
    SID get_sid(const string& v) const {
      return symbols_dict.get(v);
    }
  };

  class AID;
  typedef SVector<AID, int> AnalystVector;
  class AID : public SVectorIndex<AnalystVector> { enum { WRONG_AID}; };
  class AnalystTable {
  public:
    AnalystVector analysts;
    DictMap<int, AID> analysts_dict;

    void init() {
      analysts.push_back(-1);
      for (int c = 0; c < 10; c++) {
	  int fake_ibes_analyst_id = c + 1000;
	  analysts_dict.set(fake_ibes_analyst_id, analysts.end());
	  analysts.push_back(fake_ibes_analyst_id);
	}
    }

    AID get_aid(int v) const {
      return analysts_dict.get(v);
    }
  };
  
  double get_estimate(SID, AID) { return 0.0; }
  
  int main() {
    try {
      SymbolTable sym_table;
      sym_table.init(/* some args */);
      SymbolVector::INDEX_T sid = sym_table.get_sid("S1");
      
      AnalystTable a_table;
      a_table.init(/* some args */);
      AID aid = a_table.get_aid(1001);
      
      double estimate = get_estimate(sid, aid);
      // the line below will cause compilation break
      //double estimate = get_estimate(aid, sid);
      cerr << estimate << endl;
    } catch (Error& e) {
      cerr << "error: " << e.msg() << endl;
    }
  }
  
